package com.chen.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync // 启用Spring异步处理
public class AsyncCoConfiguration {
    @Bean("judgeTaskExecutor") // 自定义线程池Bean
    public Executor judgeTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 核心线程数（始终保持存活的线程）
        executor.setCorePoolSize(10);
        // 最大线程数（队列满后能创建的最大线程数）
        executor.setMaxPoolSize(20);
        // 任务队列容量（存放等待执行的任务）
        executor.setQueueCapacity(100);
        // 线程名前缀（方便日志追踪）
        executor.setThreadNamePrefix("judge-");
        executor.initialize();
        return executor;
    }
}